package com.shuyixiao.javan8nv1.core;

import com.shuyixiao.javan8nv1.model.Node;
import com.shuyixiao.javan8nv1.model.Connection;
import java.util.*;

public class ExecutionGraph {
    private Map<String, Node> nodes = new HashMap<>();
    private Map<String, List<Connection>> outgoing = new HashMap<>();
    private Map<String, List<Connection>> incoming = new HashMap<>();

    public void addNode(Node node) {
        nodes.put(node.getName(), node);
        outgoing.putIfAbsent(node.getName(), new ArrayList<>());
        incoming.putIfAbsent(node.getName(), new ArrayList<>());
    }

    public void addConnection(Node source, Node target, Connection connection) {
        addNode(source);
        addNode(target);
        outgoing.get(source.getName()).add(connection);
        incoming.get(target.getName()).add(connection);
    }

    public List<Node> topologicalSort() {
        // TODO: 按 v1 规则拓扑排序
        return new ArrayList<>(nodes.values());
    }

    public Map<String, Node> getNodes() {
        return nodes;
    }

    public Map<String, List<Connection>> getOutgoingConnections() {
        return outgoing;
    }

    public Map<String, List<Connection>> getIncomingConnections() {
        return incoming;
    }
} 